import 'package:amway_superapp_creator_plugin/config/colors_config.dart';
import 'package:amway_superapp_creator_plugin/viewmodels/edit/dy_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:provider/provider.dart';
import 'package:amway_superapp_creator_plugin/models/create_user_info_model.dart';
import 'input_dy_information.dart';

/*
* 抖音号
* */
class DyNumber extends StatefulWidget {
  CreateUserInfoModel info;
  final setFocus;
  String dyCode;
  String image;
  int dyState;

  DyNumber(
      {Key key,
      this.info,
      this.dyState,
      this.dyCode,
      this.image,
      this.setFocus})
      : super(key: key);

  @override
  _DyNumberState createState() => _DyNumberState();
}

class _DyNumberState extends State<DyNumber> {
  @override
  void initState() {
    super.initState();
    Provider.of<DyModel>(context, listen: false).setValue("", "", false);
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(onTap: () {
      if (widget.dyState == 1) {
        return;
      }
      widget.setFocus();
      Navigator.push(context, MaterialPageRoute(builder: (context) {
        return InputDyInformation(
            widget.info.douYinCode, widget.info.douYinQRCode.data);
      }));
    }, child: Consumer<DyModel>(builder: (context, provide, child) {
      widget.info.douYinCode = provide.isValuable
          ? ""
          : provide.account == ""
              ? widget.dyCode
              : provide.account;
      widget.info.douYinQRCode = ImagesBean(
          data: provide.image == "" ? widget.image : provide.image,
          dataType: "IMAGE",
          officialFlag: "NO");
      return Row(
        children: [
          Container(
            margin: EdgeInsets.fromLTRB(
                ScreenUtil().setWidth(16),
                ScreenUtil().setWidth(16),
                ScreenUtil().setWidth(20),
                ScreenUtil().setWidth(16)),
            child: Text("抖音号",
                style: TextStyle(
                    fontWeight: FontWeight.bold,
                    color: const Color(0xFF2C2C2C),
                    fontSize: ScreenUtil().setSp(16))),
          ),
          Expanded(
              child: Text(
            provide.account.isNotEmpty
                ? provide.account
                : widget.dyCode.isNotEmpty
                    ? widget.dyCode
                    : widget.image.isNotEmpty
                        ? ""
                        : "录入抖音信息",
            textAlign: provide.account.isNotEmpty || widget.dyCode.isNotEmpty
                ? TextAlign.start
                : TextAlign.end,
            style: TextStyle(
                color: Color(
                    provide.account.isNotEmpty || widget.dyCode.isNotEmpty
                        ? 0xff000000
                        : 0x4D000000),
                fontSize: ScreenUtil().setSp(16)),
          )),
          Container(
            child: widget.dyState == 1
                ? Image.asset(
                    "picture/icon_under_review.png",
                    package: 'amway_superapp_creator_plugin',
                    width: ScreenUtil().setWidth(80),
                    height: ScreenUtil().setWidth(30),
                  )
                : widget.dyState == 3
                    ? Image.asset(
                        "picture/icon_audit_nopass.png",
                        package: 'amway_superapp_creator_plugin',
                        width: ScreenUtil().setWidth(80),
                        height: ScreenUtil().setWidth(30),
                      )
                    : Text(""),
          ),
          provide.image.isNotEmpty || widget.image.isNotEmpty
              ? Container(
                  width: ScreenUtil().setWidth(35),
                  height: ScreenUtil().setWidth(35),
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                      color: ColorsConfig.c_F7F7F7,
                      border: Border.all(
                          color: ColorsConfig.c_d8d8d8,
                          width: ScreenUtil().setWidth(0.5)),
                      borderRadius: BorderRadius.circular(4),
                      boxShadow: [
                        BoxShadow(
                            color: ColorsConfig.c_14000000,
                            offset: Offset(0.0, 0.0), //阴影xy轴偏移量
                            blurRadius: 12.0, //阴影模糊程度
                            spreadRadius: 0.0 //阴影扩散程度
                            )
                      ]),
                  child: Image.network(
                    provide.image.isNotEmpty
                        ? provide.image
                        : widget.image.isNotEmpty
                            ? widget.image
                            : "",
                    width: provide.image.isNotEmpty
                        ? ScreenUtil().setWidth(28)
                        : widget.image.isNotEmpty
                            ? ScreenUtil().setWidth(28)
                            : 0,
                    height: provide.image.isNotEmpty
                        ? ScreenUtil().setWidth(28)
                        : widget.image.isNotEmpty
                            ? ScreenUtil().setWidth(28)
                            : 0,
                    fit: BoxFit.fill,
                  ))
              : Container(),
          Container(
              margin: EdgeInsets.only(
                  left: ScreenUtil().setWidth(5),
                  right: ScreenUtil().setWidth(12)),
              child: Image.asset(
                'picture/icon_right.png',
                package: 'amway_superapp_creator_plugin',
              ))
        ],
      );
    }));
  }
}
